/* eslint-disable */
/**
 * @name 串行执行promise集合
 * @param {promise} promises 支持一维数组和二维数组，当二维数组时，子项的第一个为成功，第二个为失败
 * @returns  promise
 */

const sequenced = function sequenced(promises) {
  if (!Array.isArray(promises)) throw new Error('Argument must be an array.');
  let promise = Promise.resolve();
  const newPromises = promises.slice(0);
  while (newPromises.length) {
    let curPromise = newPromises.shift();
    if (!Array.isArray(curPromise)) {
      curPromise = [curPromise];
    }
    const [resolve, reject] = curPromise;
    promise = promise.then(resolve, reject);
  }
  return promise;
};

export default sequenced;
